#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
#define OK  1
#define TRUE  1
#define FALSE  0
#define ERROR  0
#define OVERFLOW 0
typedef int Status;
typedef int QElemType;
typedef struct QueNode {
    QElemType data;
    struct QueNode* next;
} QueNode;
typedef struct linkQueue {
    QueNode* front;
    QueNode* rear;
} linkQueue;

Status Init_Queue(linkQueue* Q)
{
    Q->front = (linkQueue*)malloc(sizeof(linkQueue));
    Q->rear = (linkQueue*)malloc(sizeof(linkQueue));
    Q->front->next = Q->rear;
    Q->rear->next = Q->front;
}
Status IsEmpty_Queue(linkQueue* Q)
{
    if (Q->rear == Q->front) {
        return 0;
    }
    else {
        return 1;
    }
}

Status EnQueue(linkQueue* Q, QElemType e)
{
    //QueNode** head = (&Q->front);
    QueNode* newNode;
    newNode = (QueNode*)malloc(sizeof(QueNode));
    newNode->data = e;
    newNode->next = Q->rear;
    Q->front->next = newNode;
    Q->front = Q->front->next;
    //Q->front = (*head);
}
 

//Status EnQueue(linkQueue* Q,QElemType value) {
//    QueNode* new_node;
//    new_node = (QueNode*)malloc(sizeof(QueNode));
//    if (new_node == NULL)
//        perror("malloc fail\n");
//    new_node->data = value;
//    if (Q->front == NULL) {
//        Q->front = new_node;
//        Q->rear = new_node;
//    }
//    else {
//        Q->rear->next = new_node;
//        Q->rear = new_node;
//    }
//}

Status DeQueue(linkQueue* Q, QElemType* e)
{
    (*e) = Q->front->data;
    Q->front = Q->front->next;
}
int main()
{
        linkQueue Q;
        linkQueue* PQ = &Q;
        //int i, n;
        int n,m;
        int i;
        scanf("%d %d", &n, &m);
        Init_Queue(PQ);
        QueNode* head = PQ->front;
        for (i = 0; i < n; i++) {
            QElemType e;
            scanf("%d", &e);
            EnQueue(PQ, e);
        }
        PQ->front = head;
        PQ->front = PQ->front->next;
        for (i = 0; i < m; i++) {
            QElemType e = 0;
            QElemType* pe = &e;
            DeQueue(PQ, pe);
            printf("%d ", e);
        }
        printf("\n");
        printf("%d", IsEmpty_Queue(PQ));
}